package com.yorge.controller;

import com.yorge.entities.CommonResult;
import com.yorge.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {

//    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVER/payment/";
    public static final String PAYMENT_URL = "http://cloudalibaba-payment-server/payment/";

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("/getPayment/{id}")
    public CommonResult<Payment> getPayment(@PathVariable Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "getPayment/" + id, CommonResult.class);
    }

    @RequestMapping("/addPayment")
    public CommonResult<String> addPayment(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "addPayment/", payment, CommonResult.class);
    }


    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    public String echo(@PathVariable String str) {
        return restTemplate.getForObject(PAYMENT_URL + str, String.class);
    }

    @RequestMapping(value = "/getPort", method = RequestMethod.GET)
    public String getPort() {
        return restTemplate.getForObject(PAYMENT_URL + "get/getPort", String.class);
    }
}
